package com.googlecode.loframework.core
{
	import com.googlecode.loframework.controller.AccessibilityRegisterMediatorCommand;
	import com.googlecode.loframework.controller.GoBackCommand;
	import com.googlecode.loframework.controller.GoForwardCommand;
	import com.googlecode.loframework.controller.NumPagesCommand;
	import com.googlecode.loframework.controller.PersonalityQuestionChangeCommand;
	import com.googlecode.loframework.controller.QuizItemAddedCommand;
	import com.googlecode.loframework.controller.QuizItemRegisterMediatorCommand;
	import com.googlecode.loframework.controller.RemoveComponentMediatorsCommand;
	import com.googlecode.loframework.controller.StartCommand;
	import com.googlecode.loframework.model.ProjectDataProxy;
	
	import mx.core.Application;
	
	import org.puremvc.as3.interfaces.IFacade;
	import org.puremvc.as3.patterns.facade.Facade;
	
	public class LOFrameworkFacade extends Facade
	{
		/**
		 * Return singleton instance. 
		 * @return 
		 */
		public static function getInstance():IFacade
		{
			if(instance == null)
			{
				instance = new LOFrameworkFacade();
			}
			
			return instance;
		}
		
		/**
		 * Application startup function.
		 * @param appRef Reference to the main application instance.
		 */
		public static function start(appRef:Application):void
		{
			getInstance().sendNotification(NotificationNames.APP_START, appRef);
		}
		
		override protected function initializeController():void
		{
			super.initializeController();
			
			// startup command
			registerCommand(NotificationNames.APP_START, StartCommand);
			
			// numPages command
			registerCommand(NotificationNames.NUM_PAGES, NumPagesCommand);
			// go commands
			registerCommand(NotificationNames.GO_BACK, GoBackCommand);
			registerCommand(NotificationNames.GO_FORWARD, GoForwardCommand);
			
			// clean up
			registerCommand(ProjectDataProxy.PAGE_INDEX_CHANGED, RemoveComponentMediatorsCommand);
			
			// component commands
			registerCommand(NotificationNames.COMPONENT_QUIZ_ITEM_ADDED, QuizItemAddedCommand);
			registerCommand(NotificationNames.COMPONENT_QUIZ_ITEM_REGISTER_MEDIATOR, QuizItemRegisterMediatorCommand);
			// registerCommand(NotificationNames.COMPONENT_QUIZ_RESULTS_DISCOVERED, QuizResultsRegisterCommand);
			registerCommand(NotificationNames.COMPONENT_PERSONALITY_QUESTION_CHANGED, PersonalityQuestionChangeCommand);
			registerCommand(NotificationNames.COMPONENT_ACCESSIBILITY_REGISTER_MEDIATOR, AccessibilityRegisterMediatorCommand);
			// registerCommand(NotificationNames.COMPONENT_PERSONALITY_QUESTION_ADDED, PersonalityQuestionAddedCommand);
			// registerCommand(NotificationNames.COMPONENT_PERSONALITY_QUESTION_DISCOVERED, PersonalityQuestionRegisterCommand);
			
		}

	}
}